$(document).ready(
		function() {
			// 入库申请list的数据绑定
			var outStockListVue = new Vue({
				el : '#outStockListDiv',
				data : {
					items : null
				},
				methods : {
					show : function(stockApply) {
						openShowStockApplyBox(stockApply);
					},
					deleteIt : function(stockApply) {
						openDeleteConfirm(stockApply);
					}
				},
				beforeCreate : function() {
					updateOutStockApplyList();
				}
			});
			
			
			
			
			// 填写入库申请的按钮
			$("#editOutStockApplyButton").on("click", function() {
				openEditOutStockApplyBox();
			});
			
			function openDeleteConfirm(stockApply){
				layer.confirm('确认删除？', {
					btn : [ '确认', '取消' ]
				// 按钮
				}, function() {
					$.get(SERVER_PRE_URL + "stockApply/deleteStockApplyByPrimaryKeyAjax?stockApplyId="+stockApply.stockApplyId,
							function(result) {
						if (result==1) {
							layer.msg('删除成功!');
							updateOutStockApplyList();
						}else {
							layer.msg('删除失败!');
						}
						
							});
				}, function() {

				});
				
			}
			
			
			var showOutStockApplyBox=null;
			function openShowStockApplyBox(stockApply){
				showOutStockApplyBox = layer
				.open({
					type : 2,
					maxmin : true,
					title : '审核出库申请',
					offset : '4%',
					btnAlign : 'c',
					area : [ '70%', '92%' ],
					btn : [ '审核通过', '未通过' ] ,
					yes : function() {
						// 获得子窗口的值
						var childBox = layer.getChildFrame(
								'body', showOutStockApplyBox);
						var data = {
							"stockApplyId" : stockApply.stockApplyId,
							"state" : 2,
							"exameSuggestion" : childBox.find("#inputExameSuggestion").val(),
							"finish":1
						};
						baseUtil
								.httpSend(
										"stockApply/exameOutStockApplyByPrimaryKeyAjax",
										data, showExameResult);
					},
					btn2 : function() {
						// 获得子窗口的值
						var childBox = layer.getChildFrame(
								'body', showOutStockApplyBox);
						var data = {
								"stockApplyId" : stockApply.stockApplyId,
								"state" : 3,
								"exameSuggestion" : childBox.find("#inputExameSuggestion").val(),
								"finish":1
							};
							baseUtil
									.httpSend(
											"stockApply/exameOutStockApplyByPrimaryKeyAjax",
											data, showExameResult);

					},
					shadeClose : true, // 点击遮罩关闭
					content : SERVER_PRE_URL
							+ "stockApply/getStockApplyByPrimaryKeyReturnTo?stockApplyId="
							+ stockApply.stockApplyId
							+ "&returnTo=showStockApply&remark=exame"
				});
			}
			
			function showExameResult(result){
				if (result==1) {
					layer.msg('操作成功!');
					layer.close(showOutStockApplyBox);
					updateOutStockApplyList();
					
				}else {
					layer.msg('操作失败!');
				}
			}
			
			var createNewOutStockApplyBox=null;
			function openEditOutStockApplyBox(){
				createNewOutStockApplyBox = layer.open({
					type : 2,
					offset : '5%',
					maxmin : true,
					title : '填写出库申请',
					area : [ '85%', '90%' ],
					btnAlign : 'c',
					btn : [ '提交', '取消' ], // 只是为了演示
					yes : function() {
						var childBox = layer.getChildFrame('body',
								createNewOutStockApplyBox);
						var materialList = childBox.find("#materialList").val();
							
						var data={
							"remark":childBox.find("#inputRemark").val(),
							"materialList":materialList,
							"category":"out"
						};
						// 确认提交入库申请
						submitConfirm(data);	

					},
					btn2 : function() {
						layer.close();
					},
					shadeClose : true, // 点击遮罩关闭
					content : JSP_PRE_URL + 'editOutStockApply'
				});
			}
			// 确认提交入库申请
			function submitConfirm(data){
				layer.confirm('确认提交出库申请？', {
					btn : [ '确认', '取消' ]
				// 按钮
				}, function() {
					baseUtil.httpSend("stockApply/createNewOutStockApplyAjax", data, showSubmitResult);
				}, function() {

				});
			}
			
			
			//显示提交入库申请的结果
			function showSubmitResult(result){
				if (result==1) {
					layer.close(createNewOutStockApplyBox);
					layer.msg('操作成功!');
					updateOutStockApplyList();
				}else {
					layer.msg('操作失败!');
				}
			}
			
			// 更新入库申请的列表
			function updateOutStockApplyList(){
				$.get(SERVER_PRE_URL + "stockApply/getStockApplyByStateAndCategoryAjax?state=1&category=out",
						function(data) {
					outStockListVue.items = data;
						});
			}

		});